<template>
    <div>
        <vxe-modal
        ref="xTable"
        v-model="modal.visabled"
        :width="modal.width"
        :height="modal.height"
        :title="type"
        :destroy-on-close="true"
        show-footer
        @confirm="handleModalOk"
        @cancel="handleClose"
        @close="handleClose"
        >
            <template #default>
                <EvaluationForm
                v-if="ybkp"
                :jobid="jobid"
                :ybid="ybid"
                :type="type"
                :model="model"
                :ybkp="ybkp"
                :change="handlerFormChange"
                :nextNodeDbrList="nextNodeDbrList"
                ></EvaluationForm>
            </template>
            <template #footer>
                <vxe-button
                :loading="returnLoading"
                v-if="type !== '个人总结'"
                content="退回上一步"
                @click="handlerBock()"
                ></vxe-button>
                <vxe-button
                status="primary"
                content="保存"
                class="blue-btn"
                @click="handlerSave()"
                ></vxe-button>
                <vxe-button
                :loading="loading"
                status="primary"
                content="提交"
                class="blue-btn"
                @click="handlerSubmit()"
                ></vxe-button>
            </template>
        </vxe-modal>
    </div>
</template>
<script>
import {
  flowJobPage,
  queryJobByJobId,
  saveFlow,
  submitFlow,
  returnUpperFlowJob,
  queryBatchYbjcyList,
  downMyQm
} from "../api/prepareinspectorm";
import  commpVxeTable   from '@/components/commp-vxe-table/commp-vxe-table.vue'
import comVxeTable from "@/views/everydayCheck/components/vxe-table/com-vxe-table";
import EvaluationForm from "@/views/everydayCheck/prepareinspectorm/EvaluationForm";
import printInspector from './printInspector-new.vue'
import YchConstant from "@/api/YchConstant"; //接口模块配置项
export default {
    components: { comVxeTable, EvaluationForm, printInspector,commpVxeTable },
    props:{
        
    },
    data(){
        return{
            reCommpVxeTable: '',
            dataTableConfig: {
                api: YchConstant.SPZX_SPCY + '/flow-ybjcy/flowJobPage',
                rowId: 'id',
                paramet: {}
            },
            columns: [
                {
                type: "checkbox",
                width: 60,
                fixed: 'left'
                },{
                field: "fjcyxm",
                title: "姓名",
                titleInterval:true,
                slots: {
                    header:'data1_header',
                    // default:'data1_default',
                },
                width: 100,
                },
                {
                field: "fgzdw",
                title: "工作单位",
                // width: "150",
                },
                {
                field: "fqymc",
                title: "被审评单位",
                // width: "150",
                },
                {
                field: "fjclx",
                title: "审评类型",
                // width: "150",
                },
                {
                field: "fjcsj",
                title: "审评时间",
                width: 200,
                },
                {
                field: "fhjmc",
                title: "环节名称",
                width: 100,
                },
                // {
                //   field: "fdbr",
                //   title: "待办人",
                //   // width: "150",
                // },
                {
                field: "ffsrmc",
                title: "发送人",
                width: 100,
                },
                {
                field: "ffssj",
                title: "发送时间",
                width: 170,
                },
                // {
                //   field: "fblzt",
                //   title: "办理状态",
                //   // fixed:"right",
                //   // width: "150",
                // },
                {
                field: "operate",
                title: "操作",
                fixed: "right",
                width: "180",
                slots: {
                // 使用插槽模板渲染
                    default: 'operation_btn',
                },
                },
            ],
            queryParams: {},
            config: {},
            data: [],
            allAlign: null,
            formData: {
                fjcyxm: "",
                fhjmc: "",
            },
            fromItem: [
                {
                model: "fjcyxm",
                label: "姓名",
                interval:true,
                },
                {
                model: "fhjmc",
                label: "环节名称",
                placeholder: '环节名称',
                type:'Select',
                dictionaryType:'预备审评员考评流程环节'
                },
            ],
            page: flowJobPage,
            initialize: {
                fblzt: "待办",
                fhjmc: this.type,
            },
            // fndszbg 填写 大文本
            form: {},
            model: {},
            modal: {
                visabled: false,
                width: "100vw",
                height: "100vh",
                title: "",
            },
            jobid: "",
            ybid: "",
            nextNode: "",
            currentNode: '',
            saveForm: {},
            ybkp: null,
            nextNodeDbrList:[],
            checkboxArr:[],
            returnLoading: false,
            loading: false
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        async getData(row){
            const res = await queryJobByJobId({ jobid: row.jobid });
            if (res.success) {
                this.model = res.result;
                this.jobid = row.jobid;
                this.type = row.fhjmc;
                this.ybid = row.ybid;
                this.ybkp = res.result.ybkp;
                this.nextNode = res.result?res.result.nextNode:'';
                this.nextNodeDbrList = res.result.nextNodeDbrList
                this.modal.visabled = true;
            } else {
                this.$message.error(res.message);
            }
        },
        handlerFormChange(form) {
            this.saveForm = {...this.saveForm,...form};
            //console.log(this.saveForm);
        },
        handlerBock() {
            const form = this.getQueryPamas();
            if (this.type.indexOf('组长评价') !==-1){
                form.opinion = form.map.fzzyj
                if (!form.map.fzzyj) {
                this.$VxeMessage({ content: "请填写审评组长退回意见", status: "warning" });
                return;
                }
            }
            if(!form.dbrid && this.type.indexOf('经办人审核') === -1) {
                if (!form.opinion) {
                this.$VxeMessage({ content: "请填写退回办理意见", status: "warning" });
                return;
                }
            }
            this.returnLoading = true
            returnUpperFlowJob(form)
                .then((res) => {
                if (res.success) {
                    this.$VxeMessage({ content: res.message, status: "success" });
                    this.modal.visabled = false;
                    this.reCommpVxeTable = Date.now()
                } else {
                    this.$VxeMessage({ content: res.message, status: "error" });
                }
                this.returnLoading = false
            })
            .catch((error) => {
            this.$VxeMessage({ content: "未知异常", status: "error" });
            });
        },
        handlerSave() {
            const form = this.getQueryPamas();
            saveFlow(form)
                .then((res) => {
                if (res.success) {
                    this.$VxeMessage({ content: res.message, status: "success" });
                    // this.handlerEdit(form);
                    this.$emit('handlerSave')
                } else {
                    this.$VxeMessage({ content: res.message, status: "error" });
                }
            })
            .catch((error) => {
            this.$VxeMessage({ content: "未知异常", status: "error" });
            });
        },
        handlerSubmit() {
            const form = this.getQueryPamas();
            //console.log('this.type',this.type)
            //console.log('form---',form)
            if (this.type.indexOf("个人总结") !== -1) {
                //console.log('form.map.fcdjcrw',form.map.fcdjcrw)
                //console.log('form.map.fsxjcyzj',form.map.fsxjcyzj)
                if (!form.map.fcdjcrw) {
                this.$VxeMessage({ content: "请填写承担审评任务", status: "warning" });
                return;
                }
                // if (!form.map.fzzyj) {
                //   this.$VxeMessage({ content: "请填写审评组长意见及评分", status: "warning" });
                //   return;
                // }

                if (!form.map.fsxjcyzj) {
                this.$VxeMessage({
                    content: "请填写实习个人总结",
                    status: "warning",
                });
                return;
                }
            }
            if (this.type.indexOf('组长评价') !==-1) {
                if (!form.map.fzzyj) {
                this.$VxeMessage({ content: "请填写审评组长意见及评分", status: "warning" });
                return;
                }
                if (!form.map.fpj) {
                this.$VxeMessage({ content: "请选择评定等级", status: "warning" });
                return;
                }
            }
            if( this.type.indexOf('经办人审核') !== -1) {
                // if (!form.map.fpj) {
                //   this.$VxeMessage({ content: "请确定评定等级", status: "warning" });
                //   return;
                // }
            }
            this.loading = true
            submitFlow(form)
            .then((res) => {
            //console.log(res);
            if (res.success) {
                this.$VxeMessage({ content: res.message, status: "success" });
                this.modal.visabled = false;
                // this.$refs.xTable.resetEvent()
                this.reCommpVxeTable = Date.now()
                this.$emit('handlerSave')
            } else {
                this.$VxeMessage({ content: res.message, status: "error" });
            }
            this.loading = false
            })
            // .catch((error) => {
            //   this.$VxeMessage({ content: "未知异常", status: "error" });
            // });
        },
        getQueryPamas() {
            //console.log(this.saveForm);
            const { dbrid, opinion, smgflag,fsxjcyzj,fzzyj,fzzxm,fpj,fcdjcrw,ftjpj } = this.saveForm;
            const formData = {};
            formData.map = {fsxjcyzj,fzzxm,fzzyj,fpj,fcdjcrw,ftjpj};
            formData.jobid = this.jobid;
            formData.ybid = this.ybid;
            formData.nextNode = this.nextNode;
            formData.currentNode = this.currentNode;
            formData.dbrid = dbrid;
            formData.smgflag = smgflag;
            formData.opinion = opinion;
            return formData;
        },
        handleModalOk(){

        },
        handleClose(){

        },
    }
}
</script>
<style lang="less">

</style>